// page/component/new-pages/user/user.js
import requst from '../../../util/Http.js'
Page({
  data:{
    thumb:'',
    nickname:'',
    hasAddress:false,
    address:{},
  },
  onLoad(){
    var self = this;
    /**
     * 获取用户信息
     */
      let obj=wx.getStorageSync('userinfo')
      console.log(obj)
      if(obj!==undefined||obj!==null){
        self.setData({
          thumb: obj.url,
          nickname: obj.nickname
        })
      }
  },

  getaddress(){
    let token=wx.getStorageSync('token')
    if(token.length==0){
      wx.navigateTo({
        url: '/page/component/login/login',
      })
      return
    }
      wx.navigateTo({
        url: '/page/component/address/address',
      })
  },

  onShow(){
    var self = this;
    /**
     * 获取用户信息
     */
      let obj=wx.getStorageSync('userinfo')
      if(obj!==undefined||obj!==null){
        self.setData({
          thumb: obj.url,
          nickname: obj.nickname
        })
      }

    /**
     * 获取本地缓存 地址信息
     */
    wx.getStorage({
      key: 'address',
      success: function(res){
        self.setData({
          hasAddress: true,
          address: res.data
        })
      }
    })
  },

  payOrders(e){
    let {orders}=this.data
    let index=e.currentTarget.dataset.index;
    let id=orders[index].id
    wx.navigateTo({
      url: '/page/component/orders/orders?id='+id,
    })  
  },
  
  tuichu(){
    wx.clearStorage();
    wx.navigateTo({
      url: '/page/component/login/login',
    })
    this.setData({
      thumb:'',
      nickname:''
    })
  }

})